﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dm;
using System.IO;

namespace OneClick
{
    public partial class 连接信息 : Form
    {
        public string ccstr;
        string sstr;
        static DmConnection cnn = new DmConnection();
        public 连接信息()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        public string Get1()
        {   
            this.sstr = this.IP地址.Text;
            //这里只要存到文件就行了
            FileStream file_ = new FileStream("oneclick.log", FileMode.Append);
            StreamWriter file_log = new StreamWriter(file_);
            file_log.WriteLine(sstr);
            file_log.Flush();
            file_.Close();

            try
            {
                ccstr = "Server=" + IP地址.Text + "; PORT=" + 端口号.Text + "; User Id=" + 用户名.Text + "; PWD=" + 密码.Text;
                cnn.ConnectionString = ccstr;
                cnn.Open();
                TestFunc();
                //this.sstr = ("连接好了");
                cnn.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return this.sstr;
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (checkBox1.CheckState == CheckState.Checked)
            {
                Form1.Other = "Yes";
            }
            else
            {
                Form1.Other = "No";
            }

            Form1.woshibushijinglaiguo = 1;

            this.Close();
        }

        public void TestFunc()
        {
            DmCommand command = new DmCommand();
            command.Connection = cnn;
            try
            {
                string a;
                command.CommandText = "SELECT * FROM v$version; ";
            DmDataReader reader = command.ExecuteReader();
                reader.Read();
                //while (reader.Read())
                //{
                    a = reader.GetString(0);
                    this.sstr="\n"+this.sstr+"\n"+a.Split('(')[1].Split(')')[0];
                //}
            }
            catch (Exception ex)
            {
                this.sstr = (ex.Message);
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void 连接信息_Load(object sender, EventArgs e)
        {
            IP地址.Text = "10.12.21.246";
            端口号.Text = "5236";
            用户名.Text = "HNQUERY";
            密码.Text = "hnquery";

            //连接信息 load 的时候，读取好下拉框 - 和表 用户不一样，因为那个在使用过程中也要填写，这里不用
            //FileStream file_1 = new FileStream("oneclick.log", FileMode.Append);
            StreamReader file_log_1 = new StreamReader("oneclick.log");
            String line0;
            while ((line0 = file_log_1.ReadLine()) != null)
            {
                if (line0.IndexOf("$") > 0)
                {
                    continue;
                }
                IP地址.Items.Add(line0);
            }
            file_log_1.Close();
            Form1.dis_combo(sender, e, IP地址);


            //IP地址.Items.Add("10.12.21.246");
            //IP地址.Items.Add("10.12.21.251");
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
